import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILayer } from "../../../mvc/interfaces/ILayer";
import { GButton } from "../../../../com/mui/controls/GButton";
import { Language } from "../../../../extend/language/Language";
import { WindowEvent } from "../../../component/window/WindowEvent";
import { Cache } from "../../cache/Cache";
import { EActiveType } from "../../../../Message/Public/EActiveType";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { ObjCreate } from "../common/ObjCreate";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { TWedding } from "../../../../Message/Db/Tables/TWedding";
import { Alert } from "../../../../com/mui/controls/Alert";
import { BookingSceneData } from "./defin/BookingSceneData";
import { MsgManager } from "../../manager/MsgManager";
import { ItemData } from "../../resource/info/ItemData";
import { ItemsUtil } from "../shortcuts/item/ItemsUtil";
import { MarryWeddingConfig } from "../../resource/MarryWeddingConfig";
import { MoneyUtil } from "../common/util/MoneyUtil";
import { EWeddingStatus } from "../../../../Message/Game/EWeddingStatus";
import { EMarryWeddingType } from "../../../../Message/Game/EMarryWeddingType";
import { GRadioButton } from "../../../../com/mui/controls/GRadioButton";
import { NoviceGiftItemRenderer } from "../novice/NoviceGiftItemRenderer";
import { ScrollPolicy } from "../../../../flashx/textLayout/container/ScrollPolicy";
import { GiftBagConfig } from "../../resource/GiftBagConfig";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { EMarryStatus } from "../../../../Message/Game/EMarryStatus";
import { RadioButton } from "../../../../fl/controls/RadioButton";
import { GTileList } from "../../../../com/mui/controls/GTileList";
import { Vector } from "../../../../__AS3__/vec/Vector";
type int = number;
//class MarryBookingScene
    
    export  class MarryBookingScene extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this._giftArr = [34011534, 34011535];
            this._aryBtn = new Vector.<GButton>();
            this._dicRadioType = new Map<any, any> /* flash.utils.Dictionary */();
            this._aryWeddingSp = new Array<any>();
            this._aryHours = new Array<any>();
            setSize(437, 536);
            titleHeight = 26;
            title = Language.getString(43556);
            this.addEventListener(WindowEvent.SHOW, this.onShow);
            return;
        }

        public set sexType(arg1: int)
        {
            this._sexType = arg1;
            if (this._aryWeddingSp && this._aryWeddingSp.length <= 0) 
            {
                this.updateMarryScale(arg1);
            }
            if ((!Cache.instance.active.isActiveInEffect(EActiveType._EActiveTypeMarrySameSex) || this._sexType == -1) && this._tileList && this._tileList.parent) 
            {
                this._tileList.parent.removeChild(this._tileList);
                this._tileList = null;
            }
            return;
        }

        /* internal  */onShow(arg1: WindowEvent): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.MarryGetBookHours));
            this.updateState();
            return;
        }

        protected /* override */ createChildren(): void
        {
            var loc4=0;
            var loc5=0;
            var loc6=null;
            super.createChildren();
            ObjCreate.createTextField(Language.getString(43557), 21, 43, 150, 20, this, GlobalStyle.textFormat2);
            ObjCreate.createBg(18, 60, 401, 237, this);
            ObjCreate.createTextField(Language.getString(43558), 21, 305, 200, 20, this, GlobalStyle.textFormat2);
            ObjCreate.createBg(18, 328, 401, 128, this);
            this._btnOK = ObjCreate.createGButton(Language.getString(43559), 175, 459, 70, 26, this, "ButtonLarge");
            this._currentTimeDes = ObjCreate.createTextField("", 83, 336, 250, 20, this, GlobalStyle.textFormatGreen);
            this._currentTimeDes.htmlText = Language.getString(43560);
            var loc1=GlobalStyle.textFormatGreen;
            loc1.leading = 4;
            var loc2=ObjCreate.createTextField(Language.getString(43561), 24, 488, 380, 40, this, loc1);
            loc2.multiline = true;
            loc2.wordWrap = true;
            var loc3=1;
            while (loc3 < 24) 
            {
                loc4 = Math.floor((loc3 - 1) / 10);
                loc5 = (loc3 - 1) % 10;
                (loc6 = ObjCreate.createGButton(loc3.toString(), 53 + 34 * loc5, 358 + 30 * loc4, 26, 23, this, "MarryBookingTimeBtn")).addEventListener(flash.events.MouseEvent.CLICK, this.onBtnTimeClick);
                loc6.drawNow();
                this._aryBtn.push(loc6);
                ++loc3;
            }
            this._btnOK.addEventListener(flash.events.MouseEvent.CLICK, this.onClickBtnOK);
            this.updateBookHours([]);
            return;
        }

        /* internal  */onClickBtnOK(arg1: Object /* flash.events.MouseEvent */): void
        {
            var e: Object /* flash.events.MouseEvent */;
            var onSelect: Function;
            var type: int;
            var wedding: TWedding;
            var moneyName: string;
            var num: int;
            var strTips: string;
            var items: Array<any>;
            var isChooseWeddingPayBackCard: Function;
            var moneyReduce: int;
            var nowPrice: int;

            var loc1;
            onSelect = null;
            type = 0;
            wedding = null;
            moneyName = null;
            num = 0;
            strTips = null;
            items = null;
            moneyReduce = 0;
            nowPrice = 0;
            e = arg1;
            onSelect = (arg1: int): void
            {
                var loc1=0;
                var loc2=null;
                if (arg1 == Alert.OK) 
                {
                    loc1 = int(_currentSelectBtn.label);
                    loc2 = new BookingSceneData(loc1, int(_dicRadioType[_selectedRadionButton]));
                    Dispatcher.dispatchEvent(new DataEvent(EventName.MarryBookingHour, loc2));
                    hide();
                }
                return;
            }
            if (this._currentSelectBtn == null) 
            {
                MsgManager.showRollTipsMsg(Language.getString(43562));
                return;
            }
            if (this._selectedRadionButton == null) 
            {
                MsgManager.showRollTipsMsg(Language.getString(43563));
                return;
            }
            isChooseWeddingPayBackCard = (arg1: ItemData): Boolean
            {
                return ItemsUtil.isWeddingPayBackCard(arg1) && arg1.itemInfo.item.effect == wedding.unit;
            }
            type = int(this._dicRadioType[this._selectedRadionButton]);
            wedding = MarryWeddingConfig.instance.getWeddingByType(type);
            moneyName = MoneyUtil.getMoneyName(wedding.unit);
            num = this.getWeddingPrice(wedding);
            items = Cache.instance.pack.backPackCache.getItemsByJudge(isChooseWeddingPayBackCard);
            if (Cache.instance.marry.weddingStatus.status != EWeddingStatus._EWeddingStatusNotBook) 
            {
                strTips = Language.getStringByParam(43598, this._currentSelectBtn.label);
            }
            else if (items.length != 0) 
            {
                moneyReduce = (items[0] as ItemData).itemInfo.item.effectEx;
                nowPrice = num - moneyReduce;
                if (nowPrice < 0) 
                {
                    strTips = Language.getStringByParam(43627, this._currentSelectBtn.label, num.toString(), 0, moneyName);
                }
                else 
                {
                    strTips = Language.getStringByParam(43626, this._currentSelectBtn.label, num.toString(), nowPrice.toString(), moneyName);
                }
            }
            else 
            {
                strTips = Language.getStringByParam(43564, this._currentSelectBtn.label, num.toString(), moneyName);
            }
            Alert.show(strTips, null, Alert.OK | Alert.CANCEL, null, onSelect);
            return;
        }

        /* internal  */onBtnTimeClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.currentTarget as GButton;
            if (loc1.styleName == "MarryBookingTimeResultBtn") 
            {
                return;
            }
            loc1.styleName = "MarryBookingTimeResultBtn";
            loc1.drawNow();
            if (this._currentSelectBtn) 
            {
                this._currentSelectBtn.styleName = "MarryBookingTimeBtn";
            }
            this._currentSelectBtn = loc1;
            this._currentTimeDes.htmlText = Language.getStringByParam(43565, loc1.label);
            return;
        }

        /* internal  */updateMarryScale(arg1: int): void
        {
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc6=null;
            var loc7=null;
            var loc8=null;
            var loc9=null;
            var loc10=null;
            var loc1=MarryWeddingConfig.instance.getWeddingBySexType(arg1);
            var loc2=0;
            while (loc2 < loc1.length) 
            {
                loc3 = loc1[loc2];
                (loc4 = new Object /* flash.display.Sprite */()).x = 21;
                loc4.y = 67 + 58 * loc2;
                this.addChild(loc4);
                this._aryWeddingSp.push(loc4);
                (loc5 = GlobalStyle.textFormat1).leading = 4;
                (loc6 = ObjCreate.createRadioButton("", 3, -6, 30, 28, loc4)).addEventListener(flash.events.Event.CHANGE, this.onRadionButtonChange);
                loc6.groupName = "celebrationType";
                this._dicRadioType[loc6] = loc3.type;
                loc7 = ObjCreate.createTextField("", 23, 0, 80, 20, loc4);
                loc8 = ObjCreate.createTextField("", 115, 0, 150, 20, loc4);
                (loc9 = ObjCreate.createTextField("", 23, 20, 370, 40, loc4, loc5)).multiline = true;
                loc9.wordWrap = true;
                loc7.htmlText = this.getWeddingNameHtml(loc3);
                loc10 = MoneyUtil.getMoneyName(loc3.unit);
                loc8.htmlText = Language.getStringByParam(43566, this.getWeddingPrice(loc3) + loc10);
                loc9.htmlText = loc3.desc;
                ++loc2;
            }
            return;
        }

        /* internal  */getWeddingNameHtml(arg1: TWedding): string
        {
            var loc1="";
            var loc2=arg1.type;
            switch (loc2) 
            {
                case EMarryWeddingType._EMarryWeddingTypeSimple: case EMarryWeddingType._EMarryWeddingTypeNormal:
                {
                    loc1 = "<font color=\'#00FF00\'>" + arg1.name + "</font>";
                    break;
                }
                case EMarryWeddingType._EMarryWeddingTypeAdvanced:
                {
                    loc1 = "<font color=\'#00BEFF\'>" + arg1.name + "</font>";
                    break;
                }
                case EMarryWeddingType._EMarryWeddingTypeLuxury:
                {
                    loc1 = "<font color=\'#FF00FF\'>" + arg1.name + "</font>";
                    break;
                }
            }
            return loc1;
        }

        /* internal  */getWeddingPrice(arg1: TWedding): int
        {
            if (!arg1) 
            {
                return 0;
            }
            if (Cache.instance.active.isActiveInEffect(EActiveType._EActiveTypeMarrySameSex) && this._sexType > -1) 
            {
                return arg1.priceSameSex;
            }
            if (Cache.instance.active.isActiveInEffect(EActiveType._EActiveTypeBookWeddingLowPrice)) 
            {
                return arg1.lowPrice;
            }
            return arg1.price;
        }

        /* internal  */onRadionButtonChange(arg1: Object /* flash.events.Event */): void
        {
            var loc2=0;
            var loc1=arg1.currentTarget as GRadioButton;
            if (loc1.selected) 
            {
                this._selectedRadionButton = arg1.currentTarget as GRadioButton;
            }
            if (Cache.instance.active.isActiveInEffect(EActiveType._EActiveTypeMarrySameSex) && this._sexType > -1) 
            {
                loc2 = 0;
                if (this._dicRadioType[loc1] == 3) 
                {
                    loc2 = 1;
                }
                this.showGiftItems(loc2);
            }
            return;
        }

        /* internal  */showGiftItems(arg1: int): void
        {
            var loc2=null;
            if (this._tileList == null) 
            {
                this._tileList = ObjCreate.createTileList(45, 195, 340, 80, this);
                this._tileList.columnWidth = 42;
                this._tileList.rowHeight = 42;
                this._tileList.columnCount = 8;
                this._tileList.rowCount = 2;
                this._tileList.setStyle("cellRenderer", NoviceGiftItemRenderer);
                this._tileList.horizontalScrollPolicy = ScrollPolicy.OFF;
                this._tileList.verticalScrollPolicy = ScrollPolicy.OFF;
            }
            var loc1=GiftBagConfig.instance.getInfoByType(this._giftArr[arg1]);
            var loc3=[];
            var loc4=0;
            var loc5=loc1;
            for(loc2 of loc5) 
            {
                if (!(loc2.type == 3 && (loc2.career == 0 || (loc2.career & Cache.instance.role.entityInfo.career) > 0))) 
                {
                    continue;
                }
                loc3.push(loc2);
            }
            this._tileList.dataProvider = new DataProvider(loc3);
            this._tileList.drawNow();
            return;
        }

        public updateBookHours(arg1: Array<any>): void
        {
            var loc3=null;
            var loc4=0;
            var loc5=0;
            if (Cache.instance.marry.playerMarry && !(Cache.instance.marry.playerMarry.status == EMarryStatus._EMarryStatusNo)) 
            {
                if ((loc4 = Cache.instance.marry.weddingStatus.status) > EWeddingStatus._EWeddingStatusNotBook) 
                {
                    if (!(loc4 == EWeddingStatus._EWeddingStatusServerDown) && !(loc4 == EWeddingStatus._EWeddingStatusCanBook)) 
                    {
                        return;
                    }
                }
            }
            this._aryHours = arg1;
            var loc1=new Date();
            var loc2=loc1.hours;
            var loc6=0;
            var loc7=this._aryBtn;
            for(loc3 of loc7) 
            {
                if (loc3 == this._currentSelectBtn) 
                {
                    continue;
                }
                if ((loc5 = int(loc3.label)) <= loc2 || arg1.indexOf(loc5) >= 0) 
                {
                    loc3.styleName = "MarryBookingTimeBtn";
                    loc3.enabled = false;
                    continue;
                }
                loc3.enabled = true;
            }
            return;
        }

        public updateState(): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=0;
            var loc4=undefined;
            var loc5=0;
            if (Cache.instance.marry.playerMarry && !(Cache.instance.marry.playerMarry.status == EMarryStatus._EMarryStatusNo)) 
            {
                loc2 = Cache.instance.marry.weddingStatus.status;
                if (loc2 > EWeddingStatus._EWeddingStatusNotBook) 
                {
                    if (loc2 == EWeddingStatus._EWeddingStatusServerDown || loc2 == EWeddingStatus._EWeddingStatusCanBook) 
                    {
                        this._btnOK.enabled = true;
                    }
                    else 
                    {
                        this._btnOK.enabled = false;
                        loc5 = Cache.instance.marry.weddingStatus.bookDt.hours;
                        this.lockSelectOur(loc5);
                    }
                    loc3 = Cache.instance.marry.weddingStatus.weddingType;
                    var loc6=0;
                    var loc7=this._aryWeddingSp;
                    for(loc1 of loc7) 
                    {
                        loc1.mouseEnabled = false;
                        loc1.mouseChildren = false;
                    }
                    loc6 = 0;
                    loc7 = this._dicRadioType;
                    for (loc4 in loc7) 
                    {
                        if (this._dicRadioType[loc4] == Cache.instance.marry.weddingStatus.weddingType) 
                        {
                            if (typeof loc4 === "radiobutton") 
                            {
                                (loc4 as RadioButton).selected = true;
                            }
                            continue;
                        }
                        if (typeof !(loc4 === "radiobutton")) 
                        {
                            continue;
                        }
                        (loc4 as RadioButton).selected = false;
                    }
                }
            }
            else 
            {
                this._btnOK.enabled = true;
                loc6 = 0;
                loc7 = this._aryWeddingSp;
                for(loc1 of loc7) 
                {
                    loc1.mouseEnabled = true;
                    loc1.mouseChildren = true;
                }
                this.updateBookHours(this._aryHours);
            }
            return;
        }

        /* internal  */lockSelectOur(arg1: int): void
        {
            var loc1=null;
            this._currentTimeDes.htmlText = Language.getStringByParam(43567, arg1.toString());
            var loc2=0;
            var loc3=this._aryBtn;
            for(loc1 of loc3) 
            {
                if (loc1.label != arg1.toString()) 
                {
                    loc1.styleName = "MarryBookingTimeBtn";
                    loc1.enabled = false;
                }
                else 
                {
                    loc1.styleName = "MarryBookingTimeResultBtn";
                    loc1.enabled = true;
                }
                loc1.drawNow();
            }
            return;
        }

        /* internal */ /* var */_sexType: int=-1;

        /* internal */ /* var */_giftArr: Array<any>;

        /* internal */ /* var */_btnOK: GButton;

        /* internal */ /* var */_aryBtn: Vector.<GButton>;

        /* internal */ /* var */_currentTimeDes: Object /* flash.text.TextField */;

        /* internal */ /* var */_currentSelectBtn: GButton;

        /* internal */ /* var */_dicRadioType: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_selectedRadionButton: GRadioButton;

        /* internal */ /* var */_aryWeddingSp: Array<any>;

        /* internal */ /* var */_tileList: GTileList;

        /* internal */ /* var */_aryHours: Array<any>;
    }
